package top.seefly.cloudstream.interceptor;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.integration.config.GlobalChannelInterceptor;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.support.ChannelInterceptor;

/**
 * doc: https://docs.spring.io/spring-cloud-stream/docs/current/reference/html/spring-cloud-stream.html#_using_specific_binder_type_with_streambridge
 * 使用消息拦截器，拦截系统中的消息
 * @author liujianxin
 * @date 2023/07/30 11:14
 */
@Configuration
public class ChannelInterceptorConfiguration {

    @Bean
    @GlobalChannelInterceptor(patterns = "log-in-0")
    public ChannelInterceptor fooInterceptor() {
        return new ChannelInterceptor() {
            @Override
            public Message<?> preSend(Message<?> message, MessageChannel channel) {
                System.out.println("======"+message);
                return message;
            }
        };
    }

}
